home *** CD-ROM | disk | FTP | other *** search
- Path: mrnews.mro.dec.com!news
- From: Hussein Salem <salem@ehvvs5.nwg.dec.com>
- Newsgroups: comp.lang.c
- Subject: directory functions ...
- Date: Fri, 19 Jan 1996 13:42:54 +0100
- Organization: Digital Equipment SIB
- Message-ID: <30FF91CE.3F54@ehvvs5.nwg.dec.com>
- NNTP-Posting-Host: ehvvs5.nwg.dec.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (X11; I; OSF1 V3.0 alpha)
-
- Hi,
-
- I'm trying to make a small program in C handling a directory. open it and print it's content
- :
-
-
- The problem is it can't read it ! Why ? I 've set the mode to a+rwx to that direstory !
-
- These are the code and if you know what's the problem please tell me why ?
-
- -----------------
-
- #include <stdio.h>
- #include <dirent.h>
- #include <sys/types.h>
- #define MYMAX 14
-
- typedef struct {
- long ino;
- char name[MYMAX+1];
- } Dirent;
-
- main(int argc,char **argv){
- char name[MYMAX];
- DIR *dfd;
- char *dir;
- Dirent *dp;
-
- dir = "/usr/users/salem/test";
-
- if ((dfd = opendir(dir) == NULL)) {
- fprintf(stderr," can't open %s\n",dir);
- return;
- }
- printf("dir opened %s\n",dir);
- if ( (dp = readdir(dfd)) == NULL) {
- fprintf(stderr," can't read %s\n",dir);return;
- }
- while ( (dp = readdir(dfd)) != NULL) {
- printf("name = %s",dp->name);
- /*if ( !strcmp(dp->name,argv[1]) || !strcmp(dp->name,"..") ) continue;
- printf("name = %s/%s \n",dir, dp->name); */
- }
- closedir(dfd);
-
-
- }
- --
- ,,,
- (. .)
- _______________________________________________________ooO-(_)-Ooo______
- Hussein SALEM (Digital Equipment B.V.) |
- Backenmonde 2 |
- 3434 kk Nieuwegein |
- Netherlands | "One day, I'll fly away"
- Tel : (31) 30 6053725 (Home) |
- Tel : (31) 30 6088719 (Work) | Coco-Wawa
- E-mail : salem_h@cecamo.enet.dec.com (Work) |
- E-mail : salem@uto.mts.dec.com (digital) |
- ______________________________________________________________Oooo._____
- .oooO ( )
- ( ) ) /
- \ ( (_/
- \_)
-